#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
ll w[N];
int n;
ll dp[N][3];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> w[i];
  memset(dp, -0x3f, sizeof dp);
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][2]);
    dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] - w[i]);
    dp[i][2] = dp[i - 1][1] + w[i];
  }
  cout << max(dp[n][0], dp[n][2]) << endl;
}
